import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

@WebServlet("/registerAjax.do")
public class RegisterServletAjax extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //resp.setContentType("text/html; charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        JSONObject json = new JSONObject();
        if(password.length()<6){
            json.put("status", "error");
        }else {
            json.put("status", "success");
        }
//        if("123".equals(password)){
//            json.put("status", "success");
//        }else {
//            json.put("status", "error");
//        }
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(JSON.toJSONString(json));
    }



    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //resp.setContentType("text/html; charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        JSONObject json = new JSONObject();
        if("123".equals(password)){
            json.put("status", "success");
        }else {
            json.put("status", "error");
        }
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(JSON.toJSONString(json));
    }
}

